'
'   XC Engine (project Minotaur)
'   Copyright (C) 2009 Stanislav Hordiyenko
'
'   This program is free software; you can redistribute it and/or modify
'   it under the terms of the GNU General Public License as published by
'   the Free Software Foundation; either version 3 of the License, or
'   (at your option) any later version.
'
'   This program is distributed in the hope that it will be useful,
'   but WITHOUT ANY WARRANTY; without even the implied warranty of
'   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'   GNU General Public License for more details.
'
'   You should have received a copy of the GNU General Public License
'   along with this program; if not, see http://www.gnu.org/licenses
'   or write to the Free Software Foundation,Inc., 51 Franklin Street,
'   Fifth Floor, Boston, MA 02110-1301 USA
'

Class Timeout
	Private lngInterval
	Private lngAmountTime
	Private blnStarted
	Private lngStartedTime
	Private intGmtHrsOffset
	
	Private Sub Class_Initialize()
		Call Clear()
	End Sub
	
	Private Function UnixTime()
		UnixTime = DateDiff("s", "1/1/1970 00:00:00", Now()) - (3600 * intGmtHrsOffset)
	End Function
	
	Public Sub Clear()
		blnStarted = False
		intGmtHrsOffset = 2
	End Sub
	
	Public Property Let Interval(ByVal varValue)
		If InStr(1, varValue, "ms") > 0 Then
			varValue = Replace(varValue, "ms", "")
		ElseIf InStr(1, varValue, "m") > 0 Then
			varValue = Replace(varValue, "m", "")
			varValue = CInt(CDbl(varValue) * 60 * 1000)
		ElseIf InStr(1, varValue, "s") > 0 Then
			varValue = Replace(varValue, "s", "")
			varValue = CInt(CDbl(varValue) * 1000)
		Else
			varValue = CInt(varValue)
		End If
		
		lngInterval = varValue
	End Property
	
	Public Property Let Time(ByVal varValue)
		If InStr(1, varValue, "m") > 0 Then
			varValue = Replace(varValue, "m", "")
			varValue = CDbl(varValue) * 60
		ElseIf InStr(1, varValue, "s") > 0 Then
			varValue = Replace(varValue, "s", "")
			varValue = CDbl(varValue)
		Else
			varValue = CDbl(varValue)
		End If
		
		lngAmountTime = varValue
	End Property
	
	Public Property Get Occured
		Occured = False
	
		If Not blnStarted Then 
			blnStarted = True
			lngStartedTime = UnixTime()
		End If
		
		WScript.Sleep lngInterval
		
		If UnixTime()-lngStartedTime > lngAmountTime Then Occured = True
	End Property
End Class